package com.zzyl.controller.manager;


import com.zzyl.base.PageBean;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.dto.NursingProjectPageQueryDto;
import com.zzyl.entity.NursingProject;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/nursing_project")
@Api(tags = "护理项目管理口")
public class NursingProjectController {

    @Autowired
    NursingProjectService nursingProjectService;

    @ApiOperation("分页条件查询护理项目")
    /*分页查询*/
    @GetMapping
    public ResponseResult<PageBean<NursingProjectVo>> findByPage(NursingProjectPageQueryDto PageQueryDto) {
        log.info("分页查询护理项目");
        PageBean<NursingProjectVo> nursingProjectVoPage = nursingProjectService.findByPage(PageQueryDto);
        return ResponseResult.success(nursingProjectVoPage);
    }

    @ApiOperation("新增护理项目")
    @PostMapping
    public ResponseResult<Void> add(@RequestBody NursingProjectDto Dto) {
        nursingProjectService.add(Dto);
        log.info("新增护理项目成功");
        return ResponseResult.success();
    }

    @ApiOperation("根据id查询护理项目")
    @GetMapping("/{id}")
    public ResponseResult<NursingProjectVo> read(@PathVariable Long id) {
        NursingProjectVo nursingProjectVo = nursingProjectService.read(id);
        return ResponseResult.success(nursingProjectVo);
    }

    @ApiOperation("修改护理项目")
    @PutMapping
    public ResponseResult<Void> update(@RequestBody NursingProjectDto Dto) {
        nursingProjectService.update(Dto);
        log.info("修改护理项目成功");
        return ResponseResult.success();
    }

    @ApiOperation("启用禁用护理项目")
    @PutMapping("/{id}/status/{status}")
    public ResponseResult<Void> updateStatus(@PathVariable Long id, @PathVariable Integer status) {
        log.info("启用禁用护理项目成功:{} {}", id, status);
        nursingProjectService.updateStatus(id, status);
        return ResponseResult.success();
    }

    @ApiOperation("删除护理项目")
    @DeleteMapping("/{id}")
    public ResponseResult<Void> delete(@PathVariable Long id) {
        log.info("删除护理项目成功");
        nursingProjectService.delete(id);
        return ResponseResult.success();
    }

    @ApiOperation("查询所有护理项目")
    @GetMapping("/all")
    public ResponseResult<List<NursingProject>> findAll() {
        log.info("查询所有护理项目");
        List<NursingProject> list = nursingProjectService.findAll();
        return ResponseResult.success(list);
    }
}
